import {
  client
} from '@/utils/client'
const install = (Vue, vm) => {
  // shop
  let getIndex = (params = {}) => vm.$u.get('index/index', params);

  let getDecorate = (params = {}) => vm.$u.get('index/decorate', params);

  let getHotSearch = (params = {}) => vm.$u.get('index/hotLists', params);

  // account
  // 登录

  let login = (params = {}) => vm.$u.post('login/account', {
    ...params,
    terminal: client
  });

  //注册
  let register = (params = {}) => vm.$u.post('login/register', {
    ...params,
    channel: client
  });



  //向微信请求code的链接

  let getWxCodeUrl = () => vm.$u.get('login/codeUrl', {
    url: location.href
  });

  let OALogin = (params = {}) => vm.$u.post('login/oaLogin', params);

  let mnpLogin = (params = {}) => vm.$u.post('login/mnpLogin', params);


  //更新微信小程序头像昵称
  let updateUser = (data, header) => vm.$u.post('login/updateUser', data, header);


  //小程序绑定微信
  let mnpAuthBind = (data) => vm.$u.post('login/mnpAuthBind', data);

  //公众号绑定微信
  let oaAuthBind = (data) => vm.$u.post('login/oaAuthBind', data);


  // app

  //发送短信

  let smsSend = (params = {}) => vm.$u.post('sms/sendCode', params);
  let getConfig = (params = {}) => vm.$u.get('index/config', params);

  let getPolicy = (params = {}) => vm.$u.get('index/policy', params);


  let uploadImage = (file, token) => {
    return request.uploadFile({
      url: '/upload/image',
      filePath: file,
      name: 'file',
      header: {
        token
      },
      fileType: 'image'
    })
  }

  let wxJsConfig = (params = {}) => vm.$u.get('wechat/jsConfig', params);


  //user
  let getUserCenter = (params = {}) => vm.$u.get('user/center', params, {
    isAuth: false
  });

  // 个人信息
  let getUserInfo = (params = {}) => vm.$u.get('user/info', params, {
    isAuth: true
  });


  // 个人编辑
  let userEdit = (params = {}) =>
    vm.$u.post('/user/setInfo', params, {
      isAuth: true
    })

  // 绑定手机
  let userBindMobile = (params = {}, header) =>
    vm.$u.post('/user/bindMobile', params, {
      ...header,
      isAuth: true
    })

  // 微信电话
  let userMnpMobile = (params = {}) =>
    vm.$u.post('/user/getMobileByMnp', params, {
      isAuth: true
    })

  // 更改手机号
  let userChangePwd = (params = {}) =>
    vm.$u.post('/user/changePassword', params, {
      isAuth: true
    })

  //忘记密码
  let forgotPassword = (params) =>
    vm.$u.post('/user/resetPassword', params)

  //余额明细
  let accountLog = (params = {}) =>
    vm.$u.get('/account_log/lists', params)




  // news
  let getArticleCate = (params = {}) => vm.$u.get('article/cate', params);
  let getArticleList = (params = {}) => vm.$u.get('article/lists', params);
  let getArticleDetail = (params = {}) => vm.$u.get('article/detail', params);
  let addCollect = (params = {}) => vm.$u.post('article/addCollect', params, {
    isAuth: true
  });
  let cancelCollect = (params = {}) => vm.$u.post('article/cancelCollect', params, {
    isAuth: true
  });

  let getCollect = (params = {}) => vm.$u.get('article/collect', params);
  // pay

  //支付方式
  let getPayWay = (params = {}) => vm.$u.get('pay/payWay', params, {
    isAuth: true
  })

  // 预支付
  let prepay = (params = {}) => vm.$u.post('pay/prepay', params, {
    isAuth: true
  })

  // 预支付
  let getPayResult = (params = {}) => vm.$u.get('pay/payStatus', params, {
    isAuth: true
  })

  // recharge

  //充值
  let recharge = (params = {}) => vm.$u.post('/recharge/recharge', params, {
    isAuth: true
  })


  //充值记录
  let rechargeRecord = (params = {}) => vm.$u.get('/recharge/lists', params, {
    isAuth: true
  })


  // 充值配置
  let rechargeConfig = (params = {}) => vm.$u.get('/recharge/config', params, {
    isAuth: true
  })

  vm.$u.api = {
    getIndex,
    getDecorate,
    getHotSearch,

    // account
    login,
    register,
    getWxCodeUrl,
    OALogin,
    mnpLogin,
    updateUser,
    mnpAuthBind,
    oaAuthBind,
    // app
    smsSend,
    getConfig,
    getPolicy,
    uploadImage,
    wxJsConfig,
    // user
    getUserCenter,
    getUserInfo,
    userEdit,
    userBindMobile,
    userMnpMobile,
    userChangePwd,
    forgotPassword,
    accountLog,
    // article
    getArticleCate,
    getArticleList,
    getArticleDetail,
    addCollect,
    cancelCollect,
    getCollect,

    // pay
    getPayWay,
    prepay,
    getPayResult,

    // recharge
    recharge,
    rechargeRecord,
    rechargeConfig
  };
}

export default {
  install
}